#include "test.h"

#define NUM 101
#define STYLE '#'

void test1()
{
    char buffer[NUM];
    memset(buffer,0,NUM);
    const char* lable = "|/-\\";
    int len = strlen(lable);
    int cnt = 0;
    printf("正在加载中，请耐心等待...\n");
    while(cnt <= 100)
    {
        printf("[%-100s][%d%%][%c]\r",buffer,cnt,lable[cnt % len]);
        fflush(stdout);
        buffer[cnt] = STYLE;
        //sleep(2);
        usleep(50000);
        cnt++;
    }
    printf("\n加载完成！\n");

}

void test2(double current,double total)
{
    char buffer[NUM];
    memset(buffer,0,NUM);
    const char* lable = "|/-\\";
    int len = strlen(lable);
    static int cnt = 0;
    int num = (int)(100 * current / total);
    for(int i = 0;i < num;i++)
    {
        buffer[i] = STYLE;
    }
    double rate = current / total;
    cnt %= len;
    printf("[%-100s][%.1f%%][%c]\r",buffer,rate * 100,lable[cnt]);
    cnt++;
    fflush(stdout);
}
